<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html" ; charset="utf-8" />
    <title>宏宇教育信息采集</title>
    <link href="./index.css" rel="stylesheet" type="text/css" />
  </head>

  <style>
    /* .id-front .el-upload--picture-card, .id-back .el-upload--picture-card, .cun1 .el-upload--picture-card, .cun2 .el-upload--picture-card, .cun1 .el-upload--picture-card, .cun1 .el-upload--picture-card {
        display: none;
    } */
    .hide .el-upload--picture-card {
      display: none;
    }
    .box-card {
      margin: 20px 0;
    }
    
  </style>

  <body>
    <div id="app">
      <app-refund-base-information
        type="look"
        ref="baseInfo"
      ></app-refund-base-information>
      <app-education
        type="look"
        :level-list="levelList"
        v-if="isEducation"
        ref="education"
      ></app-education>
      <app-occupation
        type="look"
        v-if="isOccupation"
        ref="occupation"
      ></app-occupation>
      <app-title
        type="look"
        v-if="isTitle"
        ref="title"
      ></app-title>
      <app-train
        type="look"
        v-if="isTrain"
        ref="train"
      ></app-train>
      <app-cost-information
        type="look"
        :fee-len="feeLen"
        ref="costInfo"
        :title="costTitle"
      ></app-cost-information>
      <app-refund-info :type="type" ref="refundInfo"></app-refund-info>
      <el-card v-if="isShowResolve" class="box-card">
        <div slot="header" class="clearfix">
          <span>驳回原因</span>
        </div>
        <div>
        <el-form label-suffix=":" label-width="0" size="small">
          <el-row>
          <el-col :span="24">
            <el-form-item label="">
              <el-input type="textarea" :disabled="!typeName" v-model="denyReason" placeholder="请输入驳回信息"></el-input>
            </el-form-item>
          </el-col>
          </el-row>
        </el-form>
        </div>
      </el-card>
      <el-row>
        <el-col style="display: flex; justify-content: center">
            <template v-if="typeName">
              <el-button :disabled="isSubmit" @click="handleValid('check')" type="primary">审核通过</el-button>
              <el-button :disabled="isSubmit" @click="handleValid('resolve')" type="primary">驳回</el-button>
            </template>
            <template v-else>
              <el-button @click="handleBack('from')" type="primary">返回</el-button>
            </template>
        </el-col>
      </el-row>
    </div>

    <script src="../../../js/jquery.js"></script>
    <script src="../../../js/common.js"></script>
    <script src="../../../js/vue.js"></script>
    <script src="../../../js/element.js"></script>
    <script src="./components/RefundBaseInfo.js"></script>
    <script src="./components/EducationLevel.js"></script>
    <script src="./components/Certificate.js"></script>
    <script src="./components/Education.js"></script>
    <script src="./components/Occupation.js"></script>
    <script src="./components/Title.js"></script>
    <script src="./components/Train.js"></script>
    <script src="./components/CostInformation.js"></script>
    <script src="./components/RefundInfo.js"></script>

    <script>
      const app = new Vue({
        el: "#app",
        created() {
          this.infoName = getQuery('trainType');
          this.from = getQuery('from');
          this.typeName = getQuery('action');
        },
        mounted() {
          this.getPageTitle();
          this.getEducationOption();
          // 如果是通过操作进入当前页面，就调用获取的接口

          (this.type = getQuery("type")) && this.getStudentInfo();
        },
        data: {
          // 点击返回把当前查询页面页码返回
          pageNumber: 0,
          isSubmit: false,
          levelList: [],
          // 当前页面的名称
          infoName: '',
          typeName: '',
          type: "",
          from: '',
          feeLen: 4,
          oldData: {},
          action: "",
          // 驳回信息
          denyReason: '',
          baseInfoMap: new Map([
            ["name", "name"],
            ["phoneNum", "phone"],
            ["idNo", "idNum"],
            ["nation", "nationality"],
            ["sex", "gender"],
            ["birthday", "birthday"],
            ["address", "address"],
            ["email", "email"],
            ["qqNumber", "qq"],
            ["workAdress", "work"],
          ]),
          educationLevel: new Map([
            ["major", "discipline"],
            ["educationName", "level"],
            ["studyMode", "path"],
            ["graduateSchool", "school"],
            ["graduateTime", "time"],
            ["certificateNumber", "cerNum"],
          ]),
          educationMap: new Map([
            ["studyMode", "pathLabel"],
            ["educationName", "levelLabel"],
            ["schoolName", "schoolLabel"],
            ["majorName", "discipline"],
            ["batch", "batch"],
          ]),
          occupationKeys: [
            'professionalTypes',
            'majorName',
            'batch',
            'applyExplain',
          ],
          titleKeys: [
            'professionalLevel',
            'professionalSeries',
            'majorName',
            'batch',
          ],
          trainKeys: [
            'applyProject',
            'examCourse',
            'classs',
            'applyAssist',
            'startDate',
            'endDate',
            'batch',
          ],
          feesMap: new Map([
            ["stage", "stage"],
            ["amount", "fee"],
            ["term", "feeDate"],
            ["flag", "isFee"],
            ["receiptStatus", "receipt"],
            ["receiptNo", "receiptNum"],
          ]),
          feeMap: new Map([
            ["otherFee", "otherFee"],
            ["paidinFee", "training"],
            ["explains", "description"],
            ["allFee", "total"],
            ["preferentialFee", "discount"],
            ["realPayFee", "paid"],
          ]),
          fileList: [],
        },
        computed: {
          isEducation() {
            return this.infoName === 'education';
          },
          isOccupation() {
            return this.infoName === 'occupation';
          },
          isTitle() {
            return this.infoName === 'title';
          },
          isTrain() {
            return this.infoName === 'train';
          },
          isShowResolve() {
            return this.from !== 'bc';
          },
          costTitle() {
            const map = {
              'education': '学历',
              'occupation': '职业',
              'title': '职称',
              'train': '培训'
            };
            return map[this.infoName];
          }
        },
        methods: {
          handleBack(name) {
            var backPath = '../hotel/studentSearch.html';
            if (this.from !== 'student') {
              backPath = this.from === 'caiwu' ? '../store/moneySearch.html' : '../trade/tradeSearch.html';
            }
            window.location.href = backPath + `?pageNumber=${this.pageNumber}`;
          },
          getPageTitle() {
            // 根据查询字符串info，来判断显示哪个报考信息
            const from = getQuery('from');
            switch (from) {
                case 'jiaowu':
                    localStorage.setItem('name', '教务管理/教务信息管理/审核');
                    break;
                case 'caiwu':
                    localStorage.setItem('name', '财务管理/缴费信息管理/审核')
                    break;
                case 'fenqi':
                    localStorage.setItem('name', '学生管理/分期缴费信息查询/修改')
                    break;
            }
          },
          getRefs(key = "") {
            const {
              baseInfo = {},
              educationLevel1 = {},
              educationLevel2 = {},
              certificate = {},
              refundInfo = {},
              costInfo = {},
              education = {},
              occupation = {},
              title = {},
              train = {},
            } = this.$refs;

            return {
              baseInfo: baseInfo[key],
              educationLevel1: educationLevel1[key],
              educationLevel2: educationLevel2[key],
              certificate: certificate[key],
              refundInfo: refundInfo[key],
              costInfo: costInfo[key],
              education: education[key],
              occupation: occupation[key],
              title: title[key],
              train: train[key],
            };
          },
          handleValid(action) {
            this.action = action;
            this.isSubmit = true;
            const {
              costInfo,
            } = this.getRefs("formData");

            const reasonUrl = this.from === 'caiwu' ? baseUrl + 'studentInfo/caiwuCheck' : baseUrl + 'studentInfo/jiaowuCheck';

            // 报考流程
            let commitFlag = this.from === 'caiwu' ? 4 : 6;
            // 退款流程
            if (this.typeName  === "tuikuan" || this.typeName === 'fenqi') {
              commitFlag = this.from === 'caiwu' ? 10 : 2;
            }

            if (action === 'resolve') {
              if (!this.denyReason) {
                this.$message.error('请输入驳回消息');
                return;
              }
              commitFlag = this.from === 'caiwu' ? 3 : 5
            }

            const data = {
              studyId: getQuery('studyId'),
              userId: JSON.parse(localStorage.getItem('userInfo')).userId,
              checkType: action === 'resolve' ? 2 : 1,
              denyReason: action === 'resolve' ? this.denyReason : '',
              commitFlag,
            }

            const msg = action !== 'resolve' ? '确认审核通过?' : '是否要驳回？'
            this.$confirm(msg, '温馨提示', {
              confirmButtonText: '是',
              cancelButtonText: '否',
              type: 'warning'
            }).then(() => {
              $.ajax({
                url: reasonUrl,
                method: "post",
                headers: {
                    "Authorization": JSON.parse(localStorage.getItem('userInfo')).token
                },
                data: data,
                success: (res) => {
                    if (res.code === 200) {
                      if (action !== 'resolve') {
                        this.saveFee(commitFlag)
                      } else {
                        this.$message({
                          type: 'success',
                          message: '驳回成功!'
                        })
                        this.handleBack('from');
                      }
                    }
                }
              })
            }).catch(() => {
                      
            });
          },
          saveFee(commitFlag) {
            const { costInfo } = this.getRefs("formData");
            // const costInfo = this.$refs.costInfo.formData;
            this.oldData.fees.map((item, index) => {
              item.commitFlag = commitFlag;
              if (commitFlag == 4 || this.typeName === 'fenqi') {
                item.flag = costInfo.fees[index].isFee;
              }
              delete item.createDate;
            });

            $.ajax({
              url: baseUrl + "studentInfo/updateFee",
              method: "post",
              headers: {
                Authorization: JSON.parse(localStorage.getItem("userInfo"))
                  .token,
              },
              contentType: "application/json",
              data: JSON.stringify(this.oldData.fees),
              success: (data) => {
                this.$message({
                  type: 'success',
                  message: '审核成功!'
                });
                this.handleBack('from');
              },
            });
          },
          getStudentInfo() {
            const trainType = getQuery("trainType");
            const idNo = getQuery("idNo");
            const studyId = getQuery("studyId");

            const {
              baseInfo,
              educationLevel1: educationLevelInfo,
              educationLevel2: educationLevelInfo2,
              certificate,
              refundInfo,
              costInfo,
              education,
              occupation,
              title,
              train,
            } = this.getRefs("formData");

            $.ajax({
              url: baseUrl + "studentInfo/getStudentInfo",
              method: "get",
              headers: {
                Authorization: JSON.parse(localStorage.getItem("userInfo"))
                  .token,
              },
              data: {
                idNo,
                trainType,
                studyId,
              },
              success: (data) => {
                this.oldData = data;
                // this.id = data.student.id;
                // baseInfo.id = data.student.id;
                for (item of this.baseInfoMap) {
                  baseInfo[item[1]] = data.student[item[0]];
                }
                // if (this.from === 'jiaowu') {
                //   for (item of this.educationLevel) {
                //     educationLevelInfo[item[1]] = data.student[item[0]];
                //     educationLevelInfo2[item[1]] = data.student[item[0] + "2"];
                //   }
                // }

                if (education) {
                  for (item of this.educationMap) {
                    education[item[1]] = data.studentEducation[item[0]]
                  }
                }

                if (occupation) {
                  for (item of this.occupationKeys) {
                    occupation[item] = data.studentOccupation[item];
                  }
                }

                if (title) {
                  for (item of this.titleKeys) {
                    title[item] = data.studentTitle[item];
                  }
                }

                if (train) {
                  for (item of this.trainKeys) {
                    if (item === 'examCourse') {
                      (train[item] = data.studentTrain[item].split(','));
                    } else {
                      (train[item] = data.studentTrain[item]);
                    }
                  }
                }
                this.feeLen = data.fees.length;
                this.$nextTick(() => {
                  data.fees.map((feeItem, index) => {
                    refundInfo && (refundInfo.refundableFee = feeItem.refundableFee);
                    refundInfo && (refundInfo.deductFee = feeItem.deductFee);
                    refundInfo && (refundInfo.realRefundFee = feeItem.realRefundFee);
                    const performanceFlag = +feeItem.performanceFlag ? +feeItem.performanceFlag : ''
                    refundInfo && (refundInfo.performanceFlag = performanceFlag)
                    refundInfo && (refundInfo.refundInfo = feeItem.refundInfo);
                    refundInfo && (refundInfo.payee = feeItem.payee);

                    costInfo.otherName = feeItem.otherName;

                    for (item of this.feeMap) {
                      costInfo[item[1]] = feeItem[item[0]];
                    }
                    
                    for (feesItem of this.feesMap) {
                      if (['stage', 'fee'].includes(feesItem[1])) {
                        costInfo.fees[index][feesItem[1]] = feeItem[feesItem[0]] || undefined;
                      } else {
                        costInfo.fees[index][feesItem[1]] = feeItem[feesItem[0]];
                      }
                    }

                    this.denyReason = feeItem.denyReason;
                });
                })
                this.fileList = data.studentCards;
              },
            });
          },
          getEducationOption() {
            $.ajax({
              url: baseUrl + "education/queryEducationList",
              async: false,
              method: "Post",
              headers: {
                Authorization: JSON.parse(localStorage.getItem("userInfo"))
                  .token,
              },
              success: (data) => {
                this.levelList = data;
                console.log(`this.levelList`, this.levelList);
              },
            });
          },
        },
      });
    </script>
  </body>
</html>
